package handler

import (
	"github.com/gin-gonic/gin"
	"proj-man/models"
	"proj-man/pkg"
)

func Login(c *gin.Context) {
	username := c.PostForm("username")
	password := c.PostForm("password")
	var user models.User
	err := models.DB.Where("username = ?", username).First(&user).Error
	if err != nil {
		c.JSON(200, gin.H{
			"code": 500,
			"msg":  "没有找到该用户",
		})
		return
	}

	if user.Password != pkg.Md5Str(password) {
		c.JSON(200, gin.H{
			"code": 500,
			"msg":  "不可以登录",
		})
		return
	}

	c.JSON(200, gin.H{
		"code": 200,
		"msg":  "可以正常登录系统",
		"data": user,
	})
	return

}
